#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

const int N = 1e5 + 10;

int n, mod;
struct Node
{
    int l, r;
    LL mul;
}node[N * 4];

void pushup(int u){
    node[u].mul = node[u << 1].mul * node[u << 1 | 1].mul % mod;
}

void build(int u, int l, int r){
    node[u].l = l, node[u].r = r, node[u].mul = 1;
    if(l == r) return;
    int mid = l + r >> 1;
    build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
}

void modify(int u, int k, LL p){
    if(node[u].l == k && node[u].r == k){
        node[u].mul = p;
    }else{
        int mid = node[u].l + node[u].r >> 1;
        if(k <= mid) modify(u << 1, k, p);
        else modify(u << 1 | 1, k, p);
        pushup(u);
    }
}


void solve(){
    memset(node, 0, sizeof node);

    scanf("%d%d", &n, &mod);
    build(1, 1, n);
    int op, m;
    for(int i = 1; i <= n; i ++){
        scanf("%d%d", &op, &m);
        if(op == 1){
            modify(1, i, m);
        }else{
            modify(1, m, 1);
        }
        LL res = node[1].mul % mod;
        printf("%d\n", res);
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);
    while(T--){
        solve();
    }   
    return 0;
}